package com.example.administrator.wallet.view.activity.finds.kkbank;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.wallet.R;
import com.example.administrator.wallet.model.bean.ExchangeBalanceBean;

import java.lang.reflect.Field;
import java.lang.reflect.Method;


public class KKBankCurrencyBalanceActivity extends AppCompatActivity {

    private ImageButton bt_back;
    private TextView mV_title,tv_total_amount,tv_Total_amount_available,tv_total_amount_title,tv_KKbank_Available_amount,tv_Exchange_frozen_amount,tv_OTC_frozen_amount,tv_Amount_withdrawn,        tv_Amount_in_charge
            ;
    private ImageView iv_sign;
    private Button bt_Cash_withdrawal,bt_recharge,next;

    private ExchangeBalanceBean.DataBean dataBean;
    private String Currency;
    private  String icon;
    private String addr = "";
    private String available;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kkbank_currency_balance);

        setStatuColor();

        bt_back = (ImageButton)findViewById(R.id.finish_img);
        mV_title = (TextView)findViewById(R.id.view_title);
        iv_sign = (ImageView)findViewById(R.id.iv_sign);
        tv_total_amount_title = (TextView)findViewById(R.id.tv_total_amount_title);//总计金额标题+币种
        tv_total_amount = (TextView)findViewById(R.id.tv_total_amount);//总计金额
        tv_Total_amount_available = (TextView)findViewById(R.id.tv_Total_amount_available);//总可用金额
        tv_KKbank_Available_amount = (TextView)findViewById(R.id.tv_KKbank_Available_amount);//KK银行可用金额
        tv_Exchange_frozen_amount = (TextView)findViewById(R.id.tv_Exchange_frozen_amount);//交易所冻结金额
        tv_OTC_frozen_amount = (TextView)findViewById(R.id.tv_OTC_frozen_amount);//场外交易冻结金额
        tv_Amount_withdrawn = (TextView)findViewById(R.id.tv_Amount_withdrawn);//提现中金额
        tv_Amount_in_charge = (TextView)findViewById(R.id.tv_Amount_in_charge);//充值中金额
        bt_Cash_withdrawal = (Button) findViewById(R.id.bt_Cash_withdrawal);//提现
        bt_recharge = (Button) findViewById(R.id.bt_recharge);//充值
        next = (Button) findViewById(R.id.next);//充值

        bt_back.setVisibility(View.VISIBLE);
        mV_title.setText(R.string.KKbank);

        Currency = getIntent().getStringExtra("Currency");//获取币种
        icon = getIntent().getStringExtra("icon");//获取标志
        addr = getIntent().getStringExtra("addr");//获取币种地址
        available = getIntent().getStringExtra("available");//获取余额


        Glide.with(KKBankCurrencyBalanceActivity.this).load(icon).into(iv_sign);
        tv_total_amount.setText("0.123456"+Currency);
        tv_Total_amount_available.setText("0.123456"+Currency);
        tv_KKbank_Available_amount.setText("0.123456"+Currency);
        tv_Exchange_frozen_amount.setText("0.123456"+Currency);
        tv_OTC_frozen_amount.setText("0.123456"+Currency);
        tv_Amount_withdrawn.setText("0.123456"+Currency);
        tv_Amount_in_charge.setText("0.123456"+Currency);


        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getApplicationContext(),a3point.class));
            }
        });
        bt_Cash_withdrawal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(getApplicationContext(), CashWithdrawalOrRechargeActivity.class);
                i.putExtra("title",String.valueOf(R.string.Cash_withdrawal));
                i.putExtra("Currency",Currency);
                i.putExtra("addr",addr);
                i.putExtra("available", available);
                startActivity(i);
//                finish();
            }
        });
        bt_recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(getApplicationContext(),CashWithdrawalOrRechargeActivity.class);
                i.putExtra("title",String.valueOf(R.string.recharge));
                i.putExtra("Currency",Currency);
                i.putExtra("addr",addr);
                i.putExtra("available", available);
                startActivity(i);
//                finish();

            }
        });
        bt_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        startActivity(new Intent(getApplicationContext(),KKBankActivity.class));
        finish();
        overridePendingTransition(R.anim.pre_in_anim, R.anim.pre_out_anim);
    }
    public void setStatuColor() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(android.R.color.white));
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        setMiuiStatusBarDarkMode(this, true);
        setMiuiStatusBarDarkMode(this, true);
    }

    //设置成白色的背景，字体颜色为黑色。
    public static boolean setMiuiStatusBarDarkMode(Activity activity, boolean darkmode) {
        Class<? extends Window> clazz = activity.getWindow().getClass();
        try {
            int darkModeFlag = 0;
            Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            extraFlagField.invoke(activity.getWindow(), darkmode ? darkModeFlag : 0, darkModeFlag);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static boolean setMeizuStatusBarDarkIcon(Activity activity, boolean dark) {
        boolean result = false;
        if (activity != null) {
            try {
                WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
                Field darkFlag = WindowManager.LayoutParams.class
                        .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
                Field meizuFlags = WindowManager.LayoutParams.class
                        .getDeclaredField("meizuFlags");
                darkFlag.setAccessible(true);
                meizuFlags.setAccessible(true);
                int bit = darkFlag.getInt(null);
                int value = meizuFlags.getInt(lp);
                if (dark) {
                    value |= bit;
                } else {
                    value &= ~bit;
                }
                meizuFlags.setInt(lp, value);
                activity.getWindow().setAttributes(lp);
                result = true;
            } catch (Exception e) {
            }
        }
        return result;
    }
}
